//=============================================
//	AND Function
//=============================================

module f_and(z,x,y,en); // and function

	input [31:0] x,y;
	input en;
	output [31:0] z;

	and a1[31:0](z,x,y,en);
	

endmodule

//=============================================
//	OR Function 
//=============================================

module f_or(z,x,y,en); //or function

	input [31:0] x,y;
	input en;
	output [31:0] z;
	wire [31:0] w;        


	or o1 [31:0] (w,x,y);
         and a1[31:0] (z,w,en);



endmodule


//=============================================
//	Top module
//=============================================

module dec3to8(d,a,b,c); //3to8 decoder

	input a,b,c;
	output [7:0]d;
	wire na,nb,nc;

	not n1 (nb,b);
   	not n2 (na,a);
   	not n3 (nc,c);

	and a0(d[0],na,nb,nc);
	and a1(d[1],na,nb,c);
	and a2(d[2],na,b,nc);
	and a3(d[3],na,b,c);
	and a4(d[4],a,nb,nc);
	and a5(d[5],a,nb,c);
	and a6(d[6],a,b,nc);
	and a7(d[7],a,b,c);
	
endmodule

module ALU(z,alu,x,y, zero);

	input [31:0] x,y;
	input [2:0] alu;
	
	output [31:0] z;
	output zero;

	wire [7:0] d;
	wire [31:0] z1,z2,z3;
	wire cout1,cout2;

	dec3to8 p0(d,alu[2],alu[1],alu[0]);
	f_and	p1(z1,x,y,d[0]);
	f_or	p2(z2,x,y,d[1]);
	ALU_AdderFraction AD(.A(x), .B(y), .Result(z3), .m2(d[2]), .m6(d[6]), .m7(d[7]));
	
	or o1[31:0] (z,z1,z2,z3);

	assign zero=~|{z};

endmodule
